Crate tegra_swizzle
source ·Expand description
§tegra_swizzle
tegra_swizzle is an unofficial CPU implementation of the Tegra X1 block linear memory tiling for texture surfaces.
§Getting Started
Tiled texture data is often stored in a single buffer containing all arrays and mipmaps. This memory layout can be untiled all at once using surface::deswizzle_surface.
use tegra_swizzle::surface::{BlockDim, deswizzle_surface};
use std::num::NonZeroUsize;
// 16x16 BC7 cube map with 5 mipmaps.
let surface = deswizzle_surface(
16,
16,
1,
&swizzled_surface,
BlockDim::block_4x4(),
None,
16,
5,
6,
);
// 128x128 R8G8B8A8 2D texture with no mipmaps.
let surface = deswizzle_surface(
128,
128,
1,
&swizzled_surface,
BlockDim::uncompressed(),
None,
4,
1,
1,
);
// 16x16x16 R8G8B8A8 3D texture with no mipmaps.
let surface = deswizzle_surface(
16,
16,
16,
&swizzled_surface,
BlockDim::uncompressed(),
None,
4,
1,
1,
);
§Block Linear Memory Tiling
The surface::swizzle_surface and surface::deswizzle_surface functions implement safe and efficient tiling and untiling for the Tegra X1’s block linear format.
Block linear arranges bytes of a texture surface into a 2D grid of blocks where blocks are arranged linearly in row-major order. The tiled surface size is padded to integral dimensions in blocks, so tiled surfaces may be larger than the corresponding data in row-major order.
Groups of 512 bytes form GOBs (“group of bytes”) where each GOB is 64x8 bytes.
The block_height
parameter determines how many GOBs stack vertically to form a block.
Modules§
- Documentation for the C API.
- Functions for working with surfaces stored in a combined buffer for all array layers and mipmaps.
- Functions for tiling and untiling a single mipmap of a surface.
Enums§
- The height of each block in GOBs where each GOB is 8 bytes tall.
- Errors than can occur while tiling or untiling.
Functions§
- Calculates the block height parameter to use for the first mip level if no block height is specified.
- Calculates the division of
x
byd
but rounds up rather than truncating. - Calculates the block height parameter for the given mip level.